﻿///***************************************************************
/// 시  스  템 : Updms.Dvd
/// 단위시스템 : DVD
/// 계      층 : Presentation Layer
/// 프로그램명 : Dvd3010p
/// 파  일  명 : Dvd3010p.aspx.cs
/// 설      명 : DVD요약정보 -> 각 챠트별 상세리스트 팝업
///***************************************************************
/// 수정ID 일자       이름     내용
///---------------------------------------------------------------
/// CH001  2008-09-08 송시명   최초 작성
///***************************************************************
using System;
using System.Data;
using System.Collections;
using System.Web.UI;
using System.Web.UI.WebControls;

using SMFramework.Utility;
using SMFramework.Web.UI.WebControls.SMGridView;

using Base.Dac;
using Updms.Dvd.Exe;


namespace Updms.Dvd
{
	public partial class Dvd3010p : Updms.Common.BaseClass.PageBase
	{
		#region 전역영역

		//프로그램상수
		public static readonly string PID = "Dvd3010p";
		public static readonly string gs_path_info = "/updms/Dvd/" + PID + ".aspx";

		Global global = new Global();	

		//검색
		protected string kw1 = "";	// 출력구분 (1:배우별, 2장르별,)
		protected string kw2 = "";	// 검색어
		protected string kw3 = "";	// 라벨

		// 페이지모드

		#endregion

		#region Page_Load, OnPageLoad

		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				// 최초 화면 로딩시 처리해야 할 부분
				OnPageLoad();
				SearchProcess();
			}
		}

		// OnPageLoad
		private void OnPageLoad()
		{
			SetLiterals(global.GetLabelInfoByPgmId(PID, LANG_SET));
			SetSearchParameter();
		}

		#endregion

		#region InitializeComponent

		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);
			this.PreRender += new System.EventHandler(this.Page_PreRender);
		}

		#endregion				
		
		#region SetSearchParameter, ShowKeywordLabel

		//검색파라미터
		private void SetSearchParameter()
		{
			kw1 = String.IsNullOrEmpty(Request.QueryString["kw1"]) ? "1" : Server.UrlDecode(Request.QueryString["kw1"]);
			kw2 = String.IsNullOrEmpty(Request.QueryString["kw2"]) ? "" : Server.UrlDecode(Request.QueryString["kw2"]);
			kw3 = String.IsNullOrEmpty(Request.QueryString["kw3"]) ? "" : Server.UrlDecode(Request.QueryString["kw3"]);
		}

		//검색키워드
		private void ShowKeywordLabel()
		{
			lbl_search_keyword.Text = kw3;
		}

		#endregion	

		#region CRUD (SetDetailList, SearchProcess)

		//조회
		private void SetDetailList()
		{
			DataSet lo_ds = new DataSet();
			
			using (Dvd3010p_NT _Dvd3010p_NT = new Dvd3010p_NT())
			{
				lo_ds.Merge(_Dvd3010p_NT.GetDetailList(kw1, kw2));

				if (!DataSetUtil.CheckRowCount(lo_ds, "UPDMS_DVD_REPORT"))
				{
					CallMsgBoxInAjax("MSG_ERR_111");	// 등록된 내용이 없습니다
				}

				GridView1.DataSource = lo_ds;
				GridView1.DataBind();			

				//결과출력(키워드, 검색행수)
				ShowKeywordLabel();
			}
		}		

		//검색
		private void SearchProcess()
		{
			SetSearchParameter();
			SetDetailList();
			
			//머지
			SMGridView sGv = new SMGridView(this.Page, ref GridView1);
			
			switch (kw1)
			{
				case "1":	//배우별
					sGv.RowSpanGridView(GridView1, 1);
					sGv.RowSpanGridView(GridView1, 4);
					break;
				case "2":	//평점별
					sGv.RowSpanGridView(GridView1, 1);
					sGv.RowSpanGridView(GridView1, 5);
					break;
				case "3":	//스튜디오별
					sGv.RowSpanGridView(GridView1, 1);
					break;		
			}
		}

		#endregion	

		#region Page_PreRender, ChangePageMode

		// Page_PreRender
		private void Page_PreRender(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				using (AccessCheck access = new AccessCheck())
				{
					//접근권한 체크
					if (!access.CheckPgmAccessGrant(PID, USER_ID, ACCESS_LOG_INFO))
					{
						Response.Redirect(URL_NO_AUTHORITY_REDIRECT_POPUP);	//사용자의 권한은 요청하신 페이지를 볼 수 없습니다
					}
				}
			}
			ChangePageMode();
		}

		//ChangePageMode
		private void ChangePageMode()
		{
			SetGridViewHeader(global.GetColumnListByPgmId(PID, LANG_SET));
		}

		#endregion

		#region GridView이벤트

		//RowDataBound
		protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
		{
			if (e.Row.RowType == DataControlRowType.DataRow)
			{
				//마우스올렸을 때
				e.Row.Attributes.Add("onMouseOver", GRID_ONMOUSEOVER_COLOR);
				e.Row.Attributes.Add("onMouseOut", GRID_ONMOUSEOUT_COLOR);

				//번호
				e.Row.Cells[0].Text = (e.Row.RowIndex + 1).ToString();
			}
		}

		#endregion

		#region 버튼이벤트
	
		//엑셀
		protected void ibtn_excel_Click(object sender, EventArgs e)
		{
			SetSearchParameter();

			DataSet lo_ds = new DataSet();
			
			using (Dvd3010p_NT _Dvd3010p_NT = new Dvd3010p_NT())
			{
				lo_ds.Merge(_Dvd3010p_NT.GetDetailList(kw1, kw2));
			}
			string fileName = PID + "(" + global.GetMenuTitle(PID, LANG_SET) + ")";
			ExcelUtil.CreateExcelFileX(this.Page, fileName, lo_ds, SetExcelHeaderX(global.GetColumnListByPgmId(PID, LANG_SET)));
		}

		#endregion

	}
}
